#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    freopen("npack.in","r",stdin);
	freopen("npack.out","w",stdout);
int v[35];
int n,W;
int dp[35][20010];

    scanf("%d%d",&W,&n);
    for(int i=1;i<=n;i++)scanf("%d",&v[i]);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(j<v[i])
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i]]+v[i]);
            }
        }
    }
    printf("%d",W-dp[n][W]);

	fclose(stdin);
	fclose(stdout);
	return 0;
}

